package com.qmx.qmxapp.activity;


import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.qmx.qmxapp.R;
import com.qmx.qmxapp.base.BaseActivity;
import com.qmx.qmxapp.bean.LzyResponse;
import com.qmx.qmxapp.callback.DialogCallback;
import com.qmx.qmxapp.constant.AppConstant;
import com.qmx.qmxapp.constant.ComParamContact;
import com.qmx.qmxapp.utils.Validator;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import io.reactivex.disposables.Disposable;

/**
 * @author chengxiangtong
 * @date 2018/10/10
 */
public class RegisterAccountActivity extends BaseActivity {
    @BindView(R.id.next)
    Button next;
    private TextView tip_content;
    @BindView(R.id.edit_phone)
    EditText edit_phone;
    private Disposable disposable;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register_account);
        ButterKnife.bind(this);
        tip_content = findViewById(R.id.tip_content);
        tip_content.setText("注册账号");

    }

    /**
     * 获取code验证码
     */
    public void doPost() {
        if (!getMoblie().isEmpty()) {
            OkGo.<String>post(AppConstant.Url + ComParamContact.validMobile.PATH)
                    .params("param1", "paramValue1")
                    .execute(new DialogCallback<String>(this) {

                        @Override
                        public void onSuccess(Response<String> response) {
                            showToast(response.body());
//                            handleResponse(response);
                        }

                        @Override
                        public void onError(Response<String> response) {
                            showToast("接口有问题");
//                            handleError(response);
                        }
                    });
        }
//            EasyHttp.post("/valid/mobile")
//                    .baseUrl("http://api.smartqmx.com")
//                    .params(ComParamContact.validMobile.AREA_CODE, "+86")
//                    .params(ComParamContact.validMobile.MOBILE, "18949518508")
//                    .accessToken(true)
//                    .timeStamp(true)
//                    .execute(new CallBack<String>() {
//                        @Override
//                        public void onStart() {
//
//                        }
//
//                        @Override
//                        public void onCompleted() {
//
//                        }
//
//                        @Override
//                        public void onError(ApiException e) {
//                            showToast(e.getMessage());
//                        }
//
//                        @Override
//                        public void onSuccess(String response) {
//                            showToast(response.toString());
//                        }
//                    });
//        }
    }

    /**
     * 验证手机号
     *
     * @return
     */
    public String getMoblie() {
        if (edit_phone.getText().toString().isEmpty()) {
            showToast("手机号为空");
            return "";
        } else {
            if (!Validator.isMobile(edit_phone.getText().toString())) {
                showToast("手机号码填写有误");
                return "";
            }
            return edit_phone.getText().toString();
        }
    }

    @Override
    protected void onStart() {
        super.onStart();
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    @Override
    protected void onStop() {
        super.onStop();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @OnClick(R.id.next)
    public void onclick(View view) {
        Intent i = new Intent();
        i.putExtra("mobile", getMoblie());
        switch (view.getId()) {
            case R.id.next:
                doPost();
                i.setClass(this, CodeActivity.class);
                break;
        }
        startActivity(i);
    }

    private class RxJavaCallAdapterFactory {
    }


    //在需要取消网络请求的地方调用,一般在onDestroy()中
    //EasyHttp.cancelSubscription(disposable);
}
